#include <iostream>

using namespace std;

// 桥接模式的核心为: 抽象的 A 使用/应用 抽象的 B

class Animal;

class Tools;

class Animal {
public:
    explicit Animal(Tools *tools) : tools(tools) {
    }

    virtual ~Animal() {
        delete tools;
    };

protected:
    Tools *tools = nullptr;

public:
    virtual void useTools() = 0;
};

class Tools {
public:
    virtual ~Tools() = default;

public:
    virtual void doSomeThing() = 0;
};

class Dog : public Animal {
public:
    explicit Dog(Tools *tools) : Animal(tools) {}

    ~Dog() override = default;

public:
    void useTools() override {
        cout << "Dog Use ";
        tools->doSomeThing();
    }
};

class Cat : public Animal {
public:
    explicit Cat(Tools *tools) : Animal(tools) {}

    ~Cat() override = default;

public:
    void useTools() override {
        cout << "Cat Use ";
        tools->doSomeThing();
    }
};

class ATools : public Tools {
public:
    ~ATools() override = default;

public:
    void doSomeThing() override {
        cout << "Tools A Do Some Thing!" << endl;
    }
};

class BTools : public Tools {
public:
    ~BTools() override = default;

public:
    void doSomeThing() override {
        cout << "Tools B Do Some Thing!" << endl;
    }
};

void test01() {
    Tools *tools = nullptr;
    Animal *animal = nullptr;

    tools = new ATools();
    animal = new Cat(tools);

    animal->useTools();

    delete animal;

    cout << endl;
}

void test02() {
    Tools *tools = nullptr;
    Animal *animal = nullptr;

    tools = new BTools();
    animal = new Dog(tools);

    animal->useTools();

    delete animal;

    cout << endl;
}


int main() {
    test01();

    test02();

    return 0;
}
